﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using YJKRoomInspection.Model;
using YArchitech.Controls;
using YArchitech.LIB;

namespace YJKRoomInspection.Utiltiy
{
	internal static class XmlManger
	{
		internal static XmlElement FindTypeXmlElement()
		{
			string userDirectoryFile = XmlManger.GetUserDirectoryFile(StaticRescource.TypeXmlName);
			File.Exists(userDirectoryFile);
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(userDirectoryFile);
			return xmlDocument.DocumentElement;
		}

		internal static List<FrontChamberTypeRule> GetTypeXmlValue()
		{
			XmlElement xmlElement = XmlManger.FindTypeXmlElement();
			List<FrontChamberTypeRule> list = new List<FrontChamberTypeRule>();
			string empty = string.Empty;
			if (xmlElement == null)
			{
				return null;
			}
			foreach (object obj in xmlElement.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				FrontChamberTypeRule frontChamberTypeRule = new FrontChamberTypeRule();
				frontChamberTypeRule.name = xmlNode.Name;
				if (xmlNode is XmlElement)
				{
					foreach (object obj2 in xmlNode.ChildNodes)
					{
						XmlNode xmlNode2 = (XmlNode)obj2;
						frontChamberTypeRule.TypeRule.Add(xmlNode2.Name, int.Parse(xmlNode2.InnerText));
					}
				}
				list.Add(frontChamberTypeRule);
			}
			return list;
		}

		public static string GetUserDirectoryFile(string strDataFileName)
		{
			try
			{
				string text = Product.DataLocation + strDataFileName;
				bool exists = new FileInfo(text).Exists;
				return text;
			}
			catch
			{
				YJKMessageBox.Show("初始化用户数据文件(" + strDataFileName + ")失败。");
			}
			return "";
		}

		internal static XmlElement FindStandardXmlElement()
		{
			string userDirectoryFile = XmlManger.GetUserDirectoryFile(StaticRescource.StandardXmlName);
			File.Exists(userDirectoryFile);
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(userDirectoryFile);
			return xmlDocument.DocumentElement;
		}

		internal static List<FrontChamberStandardRule> GetStandardXmlValue()
		{
			XmlElement xmlElement = XmlManger.FindStandardXmlElement();
			List<FrontChamberStandardRule> list = new List<FrontChamberStandardRule>();
			string empty = string.Empty;
			if (xmlElement == null)
			{
				return null;
			}
			foreach (object obj in xmlElement.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (xmlNode is XmlElement)
				{
					foreach (object obj2 in xmlNode.ChildNodes)
					{
						XmlNode xmlNode2 = (XmlNode)obj2;
						FrontChamberStandardRule frontChamberStandardRule = new FrontChamberStandardRule();
						frontChamberStandardRule.RoomType = xmlNode2.ParentNode.Name;
						frontChamberStandardRule.BuildingType = xmlNode2.Name;
						foreach (object obj3 in xmlNode2.ChildNodes)
						{
							XmlNode xmlNode3 = (XmlNode)obj3;
							frontChamberStandardRule.StandardRule.Add(xmlNode3.Name, double.Parse(xmlNode3.InnerText));
						}
						list.Add(frontChamberStandardRule);
					}
				}
			}
			return list;
		}
	}
}
